/**
 * @file    errors.c
 * @author  Thomas Di'Meco and Matthieu Maugard
 * @brief   Errors helpers
 */

#include <stdlib.h>
#include "errors.h"


/**
 * Get the string equivalent of an error id
 * @param errno The error id
 * @return The equivalent string error
 */
const char * error_string (int errno)
{
    // Define error string (errno >= 0)
    const char * error_str[] =
    {
        "no error",                 // 0
        "invalid argument",         // 1
        "assembly failed",          // 2
        "unknown instruction",      // 3
        "invalid instruction mode", // 4
        "invalid register number",  // 5
        "invalid memory address",   // 6
        "invalid stack address",    // 7
        "reached memory limit"      // 8
    };

    // Define others error string
    const char * halt_error_str    = "halted",
               * unknown_error_str = "unknown error";

    int size = sizeof(error_str) / sizeof(error_str[0]);

    if (errno < 0)
        return halt_error_str;
    else if (errno < size)
        return error_str[errno];

    return unknown_error_str;
}
